import Vue from 'vue'
import Router from 'vue-router'
import Home from './views/HomeView.vue'
import Login from './views/LoginView.vue'
import VideoUpload from './views/VideoUpload.vue'
import HelloWorld from './components/HelloWorld.vue'

Vue.use(Router)

const router = new Router({
    routes: [
        {
            path: '/',
            component: Home,
            children: [
                { path: '', component: HelloWorld }

            ]
        },
        {
            path: '/login',
            name: 'Login',
            component: Login
        },
        {
            path: '/videoUpload',
            name: 'VideoUpload',
            component: VideoUpload
        }
    ]
})

router.beforeEach((to, from, next) => {
    const token = localStorage.getItem('token')
    if (!token && to.name !== 'Login') {
        next('/login')
    } else {
        next()
    }
})

export default router
